#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int dieSimulator(int n, vector<int>& rollMax) {
        vector<vector<int>> dp(n + 1, vector<int>(6));
        vector<int> sum(n + 1);
        int mod = 1e9 + 7;
        for (int j = 0; j < 6; j++) dp[1][j] = 1;
        sum[1] = 6, sum[0] = 1;
        for (int i = 2; i <= n; i++)
            for (int j = 0; j < 6; j++)
            {
                int pos = max(i - 1 - rollMax[j], 0);
                int d = ((i - 1 - rollMax[j] < 0 ? 0 : sum[pos] - dp[pos][j]) + mod) % mod;
                dp[i][j] = ((sum[i - 1] - d) + mod) % mod;
                sum[i] = (sum[i] + dp[i][j]) % mod;
            }
        return sum[n];
    }
};